//
//  JiGuangUnit.m
//  智云网校
//
//  Created by Damon on 2017/6/29.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "JiGuangUnit.h"
//#import "JPUSHService.h"
//#import "JSHAREService.h"
//#import "JANALYTICSService.h"
#import "NSString+Additions.h"
#import "UIAlertController+Common.h"
//#import "MQChatViewManager.h"
//#import "WXApi.h"
#import <UserNotifications/UserNotifications.h>
//#import "ArgumentController.h"
//#import "XMCourseDetailViewController.h"
//#import "BuyCourseController.h"
//#import "TopicCorrectController.h"
#import "AppDelegate.h"
#import "ShareView.h"
//#import "TalkfunViewController.h"
//#import "XMCourseDetailModel.h"
//#import "WebDViewController.h"
#warning 王旭 百家云
//#import "BJRoomViewController.h"
//#import "PMPlayerViewController.h"
//#import "BJEnterRoomViewController.h"
#import <BJLiveUI/BJLiveUI.h>
//#import "PUPlayViewController.h"
#import <BJPlaybackUI/BJPlaybackUI.h>

//@interface JiGuangUnit ()<JPUSHRegisterDelegate>
@interface JiGuangUnit ()


@property (nonatomic, strong) ShareView *shareView;
//@property (nonatomic, strong) JSHAREMessage *message;

@end


@implementation JiGuangUnit

static JiGuangUnit * shared = nil;

+ (instancetype)sharedInstant{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shared = [[JiGuangUnit alloc] init];
    });
    return shared;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)setupConfigureView {
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
        
    @weakify(self)
    //美恰客服
//    [MQManager initWithAppkey:kMQKEY completion:^(NSString *clientId, NSError *error) {
//        @strongify(self)
//        if (error) {
//            NSLog(@"clientID: %@ , error :%@",clientId,error.description);
//        }
//        [MQManager setCurrentClientOnlineWithSuccess:^(MQClientOnlineResult result, MQAgent *agent, NSArray<MQMessage *> *messages) {
//            NSLog(@"MQ设置用户上线回调成功：%lu",(unsigned long)result);
//        } failure:^(NSError *error) {
//            NSLog(@"MQ设置用户上线回调失败：%@",error);
//        } receiveMessageDelegate:self];
//
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNewMQMessages:) name:MQ_RECEIVED_NEW_MESSAGES_NOTIFICATION object:nil];
//
//    }];
    
    //创建下载路径
    [FileManagerUtil createDirectoryDownloadFolder];
    
    //注册微信支付
//    [WXApi registerApp:JShareWXAppID];
    
    
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    
    
}
#pragma mark - JShare
- (void)setupConfigureJShare{
//    JSHARELaunchConfig *config = [[JSHARELaunchConfig alloc] init];
//    config.appKey = @"111";
//    config.SinaWeiboAppKey = JShareSinaWeiboAppKey;
//    config.SinaWeiboAppSecret = JShareSinaWeiboAppSecret;
//    config.SinaRedirectUri = JShareSinaWeiboCallback;
//    config.QQAppId = JShareQQAppID;
//    config.QQAppKey = JShareQQAppKey;
//    config.WeChatAppId = JShareWXAppID;
//    config.WeChatAppSecret = JShareWXAppSecret;
    
//    [JSHAREService setupWithConfig:config];
//    [JSHAREService setDebug:NO];
    
    
    //统计分析
//    JANALYTICSLaunchConfig * configA = [[JANALYTICSLaunchConfig alloc] init];
//    configA.appKey = JPushAppKey;
//    configA.channel = JAppChannel;
//    [JANALYTICSService setupWithConfig:configA];
    
    CLLocation * location = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(116.46, 39.92) altitude:50 horizontalAccuracy:50 verticalAccuracy:50 timestamp:[NSDate date]];
//    [JANALYTICSService setLocation:location];
    //[JANALYTICSService crashLogON];
}

#pragma mark- JPUSH  JPUSHRegisterDelegate
- (void)setupConfigureJPush:(NSDictionary *)lanuchOptions{
//    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
//    entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;

//    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
//    [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
//        NSLog(@"resCode :%d , registrationID :%@",resCode,registrationID);
//    }];
    BOOL isProduct = YES;
    
#if DEBUG
    isProduct = NO;
#else
    isProduct = YES;
#endif
    
//    [JPUSHService setupWithOption:lanuchOptions appKey:JPushAppKey
//                          channel:JAppChannel
//                 apsForProduction:isProduct //生产YES，开发NO
//            advertisingIdentifier:nil];
    
    NSLog(@"==================%d",isProduct);
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
//    [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
    
    [self clearApplicationNotification_APNS];
    
    
    if (lanuchOptions) {
        NSLog(@"lanuchOptions:%@",lanuchOptions);
        NSDictionary *remoteNotification = [lanuchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
        NSNumber * code = remoteNotification[RESPONSE_CODE];
        if (code.integerValue == CODE_LOGOUT) {//退出登录
            [self showAlertLogin:remoteNotification[RESPONSE_MSG]];
            return;
        }

        if (code.integerValue == CODE_MAILBOX) {//首页信箱
//            [self showRedPointNotification];
            NSDictionary * resData = remoteNotification[RESPONSE_DATA];

            if ([SettingObject objectIsValid:resData]) {//课程消息 跳转
                if ([SettingObject objectIsValid:resData[@"course_type"]] && [SettingObject objectIsValid:resData[@"course_id"]]) {
                    NSDictionary *couseDict = @{@"course_type"  : resData[@"course_type"] ? : @"",
                                                @"course_id"    : resData[@"course_id"]   ? : @""};
                    [self receiveAPNSWithPushViewController:couseDict];
                }
            }
        }else if (CODE_PUSHVC == code.integerValue){
            NSDictionary * resData = remoteNotification[RESPONSE_DATA];
            if ([SettingObject objectIsValid:resData]) {
                if ([SettingObject objectIsValid:resData]) {
                    [self receiveAPNSWithPushViewController:resData];
                }
            }
            return;
        }
    }
}

#pragma mark - 监听收到美洽聊天消息的广播
//- (void)didReceiveMQMessages:(NSArray<MQMessage *> *)message{
//    [self pushMQMessageVC:message];
//}
- (void)didReceiveNewMQMessages:(NSNotification *)notification {
    //广播中的消息数组
    NSArray *messages = [notification.userInfo objectForKey:@"messages"];
//    [self pushMQMessageVC:messages];
    NSLog(@"监听到了收到客服消息的广播");
}

/*
- (void)pushMQMessageVC:(NSArray *)messages{
    if([SettingObject objectIsValid:messages]){
        for (MQMessage *msg in messages) {
            //【系统消息】您好，由于很久没有收到您的消息，系统自动结束了对话。如果还有需要，欢迎随时联系我们。
            if([msg.content rangeOfString:@"【系统消息】"].location !=NSNotFound){
                return;
            }
        }
        if ([[SettingObject topViewController] isKindOfClass:[MQChatViewManager class]]
            || [[SettingObject getCurrentViewController] isKindOfClass:[MQChatViewManager class]]) {
            return;
        }
        //NSString *string = [NSString stringWithFormat:@"您收到%ld条客服新信息",messages.count ? : 0];
        NSString *string = [NSString stringWithFormat:@"您有新的客服信息"];
        UIAlertController * alert = [UIAlertController showAlertController:@"" message:string style:UIAlertControllerStyleAlert];
        [alert addAction:@"立即查看" style:UIAlertActionStyleDefault handler:^(UIAlertAction *al) {
            MQChatViewManager *chatViewManager = [[MQChatViewManager alloc] init];
            [chatViewManager setLoginCustomizedId:[UserModel shareInstance].uid];
            MQChatViewStyle *aStyle = [chatViewManager chatViewStyle];
            [aStyle setNavBarTintColor:[UIColor whiteColor]];
            [chatViewManager pushMQChatViewControllerInViewController:[SettingObject topViewController]];
        }];
        [alert addAction:@"稍后查看" style:UIAlertActionStyleCancel handler:^(UIAlertAction *al) {}];
        [alert presentViewController:nil];
    }
}
*/


//JPush 收到自定义消息
- (void)networkDidReceiveMessage:(NSNotification *)notification {
    NSDictionary * userInfo = [notification userInfo];
    NSNumber * code = [userInfo valueForKey:@"extras"][RESPONSE_CODE];
    if (code.integerValue == CODE_LOGOUT) {//退出登录
        [self showAlertLogin:[userInfo valueForKey:@"extras"][RESPONSE_MSG]];
        return;
    }
    if (code.integerValue == CODE_MAILBOX) {//首页信箱
        [self showRedPointNotification];
    }
}
- (void)showRedPointNotification{
//    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_SHOWREDPOINT object:@(YES)];
//    [DUserDefault setDataObject:@(YES) forKey:NOTIFICATION_SHOWREDPOINT];
}
//重新登陆
- (void)showAlertLogin:(NSString *)message{
//    UIAlertController *alert = [UIAlertController showAlertController:@"收到新消息" message:message ? : @"" style:UIAlertControllerStyleAlert];
    UIAlertController *alert = [UIAlertController showAlertController:@"" message:@"您的账号已在其他设备登陆" style:UIAlertControllerStyleAlert];
    [alert addAction:@"重新登陆" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alertAction) {
        AppDelegate *appdelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
//        [appdelegate toLoginViewContrller];
    }];
    [alert presentViewController:nil];
}

// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    @try {
        // Required
        NSDictionary * userInfo = notification.request.content.userInfo;
//        NSLog(@"推送消息是=======%@",userInfo)
        if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//            [JPUSHService handleRemoteNotification:userInfo];
        }
        NSNumber * code = userInfo[RESPONSE_CODE];
        if (code.integerValue == CODE_LOGOUT) {//退出登录
            [self showAlertLogin:userInfo[RESPONSE_MSG] ? : @""];
            return;
        }

        if (code.integerValue == CODE_MAILBOX) {//首页信箱
//            [self showRedPointNotification];
            return;
        }
        
//        if (CODE_PUSHVC == code.integerValue){
//            NSDictionary * resData = userInfo[RESPONSE_DATA];
//            if ([SettingObject objectIsValid:resData]) {
//                if ([SettingObject objectIsValid:resData]) {
//                    [self receiveAPNSWithPushViewController:resData];
//                }
//            }
//            return;
//        }

    } @catch (NSException *exception) {
        NSLog(@"exception:%@",exception);
    } @finally {
        completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法，选择是否提醒用户，有Badge、Sound、Alert三种类型可以选择设置
    }
}
// iOS 10 Support 后台，未完全退出
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    @try {
        NSLog(@"jpush 222");
        // Required
        NSDictionary * userInfo = response.notification.request.content.userInfo;
        if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//            [JPUSHService handleRemoteNotification:userInfo];
        }
        NSNumber * code = userInfo[RESPONSE_CODE];
        if (code.integerValue == CODE_LOGOUT) {//退出登录
            [self showAlertLogin:userInfo[RESPONSE_MSG] ? : @""];
            return;
        }

        if (code.integerValue == CODE_MAILBOX) {//首页信箱- 普通消息
            [self showRedPointNotification];
            NSDictionary * resData = userInfo[RESPONSE_DATA];
            if ([SettingObject objectIsValid:resData]) {
                if ([SettingObject objectIsValid:resData[@"course_type"]] && [SettingObject objectIsValid:resData[@"course_id"]]) {
                    NSDictionary *couseDict = @{@"course_type"  : resData[@"course_type"] ? : @"",
                                                @"course_id"    : resData[@"course_id"]   ? : @""};
                    [self receiveAPNSWithPushViewController:couseDict];
                }
            }
            return;
        }else if (CODE_PUSHVC == code.integerValue){
            NSDictionary * resData = userInfo[RESPONSE_DATA];
            if ([SettingObject objectIsValid:resData]) {
                if ([SettingObject objectIsValid:resData]) {
                    [self receiveAPNSWithPushViewController:resData];
                }
            }
            return;
        }
        
    } @catch (NSException *exception) {
        NSLog(@"exception:%@",exception);
    } @finally {
        completionHandler();  // 系统要求执行这个方法
    }
}

- (void)clearApplicationNotification_APNS{
    //角标
//    [JPUSHService resetBadge];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}


static BOOL pushing = NO;

//推送通知跳转
- (void)receiveAPNSWithPushViewController:(NSDictionary *)dict{
    //1直播；2点播；3面授；4申论批改
    
//    if (pushing) {
//        return;
//    }
//    
//    pushing = YES;
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        pushing = NO;
//    });
//
//    NSLog(@"收到推送=====%@",dict);
//    
//    if (1) {
//        return;
//    }
//
//    else {
//        NSUInteger index = [dict[@"course_type"] integerValue];
//        if (![SettingObject objectIsValid:dict[@"course_id"]]) {
//            return;
//        }
//        if (index == 4) {
//            [self downLoadDataWithDic:dict];
//        }else if (index == 3){
////            ArgumentController *argumentViewController = [[ArgumentController alloc] init];
////            argumentViewController.argumentDic = dict;
////            [SettingObject pushviewController:argumentViewController];
//        }else if(index == 1){
////            XMCourseDetailViewController *detailViewController = [[XMCourseDetailViewController alloc] init];
////            detailViewController.params = dict;
////            [SettingObject pushviewController:detailViewController];
//        }else if(index == 5){
//#warning 王旭修改 推送 直播 百家云
//            NSString *openUrl=dict[@"openUrl"];
//            if (!openUrl) {
//                return;
//            }
//            //推送只有直播课
//            
//#warning 王旭 欢脱云改为百家云
//            UserModel *UM=[UserModel shareInstance];
//            NSString *url=@"";
//            SGParameter *parameter = [[SGParameter alloc] init];
//            NSString *videoid = openUrl ?: @"";
//            
//            url = [NSString stringWithFormat:@"%@%@",[OtherNetworking sharedManager].STRURL,@"NewCourse/bjy_zb_sign"];
//            parameter.body.data = @{@"video_id":videoid,@"uid":UM.uid,@"user_nicename":UM.user_nicename,@"avatar":UM.avatar};
//            
//           // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//            [SGHttpTool POST:url parameter:parameter sucess:^(id result) {
//              //  [MBProgressHUD hideHUDForView:self.view animated:YES];
//                Class class =NSClassFromString(@"BJPlayModel");
//                SGReceive *receive = [SGReceive receiveWithResponseObject:result dataClass:class];
//                
//                NSInteger code = [receive.code intValue];
//                if (code == 2000) {
//                    BJPlayModel *resModel = receive.data;
//                    
//                    BJLRoomViewController *roomViewController = [BJLRoomViewController
//                                                                 instanceWithID:resModel.video_id
//                                                                 apiSign:resModel.token
//                                                                 user:[BJLUser
//                                                                       userWithNumber:UM.uid
//                                                                       name:UM.user_nicename
//                                                                       avatar:UM.avatar
//                                                                       role:BJLUserRole_student]];
//                    UIViewController * vc = [SettingObject topViewController];
//                    [vc presentViewController:roomViewController animated:NO completion:nil];
//                    // roomViewController.delegate = self;
//                    
//                    
//                    
//                }
//            } failure:^(id reslut) {
//               // [MBProgressHUD hideHUDForView:self.view animated:YES];
//            }];
//            
//            /*
//            TalkfunViewController *myVC = [[TalkfunViewController alloc] init];
//            myVC.token = dict[@"access_token"];
//             
//            
//            if (dict[@"access_token"]) {
//                UIViewController * vc = [SettingObject topViewController];
//                PERFORM_IN_MAIN_QUEUE([vc presentViewController:roomViewController animated:NO completion:nil];)
//            }
//             */
//        }else if (index == 2){//公开课
//            
//            [self playVideo:dict];
//        }else if (index == 0){//网页
//            NSString * str = dict[@"url"];
//            WebDViewController * vc = [[WebDViewController alloc] init];
//            vc.urlString = str;
//            [SettingObject pushviewController:vc];
//        }
//    }
    
}

- (void)playVideo:(NSDictionary*)dict
{
    if (!dict[@"openUrl"]) {
        return;
    }
//推送只有直播
#warning 王旭修改推送播放视频流程
    
  
    NSString *openUrl=dict[@"openUrl"];
    if (!openUrl) {
        return;
    }
    //推送只有直播课
    
//#warning 王旭 欢脱云改为百家云
//    UserModel *UM=[UserModel shareInstance];
//    NSString *url=@"";
//    SGParameter *parameter = [[SGParameter alloc] init];
//    NSString *videoid = openUrl ?: @"";
//
//    url = [NSString stringWithFormat:@"%@%@",[OtherNetworking sharedManager].STRURL,@"NewCourse/bjy_zb_sign"];
//    parameter.body.data = @{@"video_id":videoid,@"uid":UM.uid,@"user_nicename":UM.user_nicename,@"avatar":UM.avatar};
//
//    // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    [SGHttpTool POST:url parameter:parameter sucess:^(id result) {
//        //  [MBProgressHUD hideHUDForView:self.view animated:YES];
//        Class class =NSClassFromString(@"BJPlayModel");
//        SGReceive *receive = [SGReceive receiveWithResponseObject:result dataClass:class];
//
//        NSInteger code = [receive.code intValue];
//        if (code == 2000) {
//            BJPlayModel *resModel = receive.data;
//
//            BJLRoomViewController *roomViewController = [BJLRoomViewController
//                                                         instanceWithID:resModel.video_id
//                                                         apiSign:resModel.token
//                                                         user:[BJLUser
//                                                               userWithNumber:UM.uid
//                                                               name:UM.user_nicename
//                                                               avatar:UM.avatar
//                                                               role:BJLUserRole_student]];
//            UIViewController * vc = [SettingObject topViewController];
//            [vc presentViewController:roomViewController animated:NO completion:nil];
//            // roomViewController.delegate = self;
//
//
//
//        }
//    } failure:^(id reslut) {
//        // [MBProgressHUD hideHUDForView:self.view animated:YES];
//    }];
    
}

#warning 王旭 百家云播放新方法
-(void)pushBJViewControllerToken:(NSString *)token videoId:(NSString *)videoId
{
//    UserModel *UM=[UserModel shareInstance];
//    BJLRoomViewController *roomViewController = [BJLRoomViewController
//                                                 instanceWithID:videoId
//                                                 apiSign:token
//                                                 user:[BJLUser
//                                                       userWithNumber:UM.uid
//                                                       name:UM.user_nicename
//                                                       avatar:UM.avatar
//                                                       role:BJLUserRole_student]];
//
//
//        UIViewController * vc = [SettingObject topViewController];
//        PERFORM_IN_MAIN_QUEUE([vc presentViewController:roomViewController animated:NO completion:nil];)
   
}


//- (void)pushTalkfunViewController:(XMCourseDetailTalkfunModel *)model openId:(NSString*)openId{
//    if (model.code.integerValue == 0) {
//
//        TalkfunViewController *myVC = [[TalkfunViewController alloc] init];
//        myVC.token = model.data[@"access_token"];
//        myVC.openShare = YES;
//
//
//
//        if (model.data[@"access_token"]) {
//            UIViewController * vc = [SettingObject topViewController];
//            PERFORM_IN_MAIN_QUEUE([vc presentViewController:myVC animated:NO completion:nil];)
//        }
//    }else{
//        NSLog(@"error msg:%@",model.msg);
//    }
//}



- (void)downLoadDataWithDic:(NSDictionary*)dic{
//    NSString *url = [NSString stringWithFormat:@"%@%@",[OtherNetworking sharedManager].STRURL,@"Course/details"];
//    SGParameter *parameter = [[SGParameter alloc] init];
//    parameter.body.data = dic;
//    [SGHttpTool POST:url parameter:parameter sucess:^(id result) {
//        SGReceive *receive = [SGReceive receiveWithResponseObject:result dataClass:NSClassFromString(@"CorrectModel")];
//        NSInteger code = [receive.code intValue];
//        if (code != 2000) {
//            NSLog(@"receive.msg;%@",receive.msg);
//        } else {
//            CorrectModel *correctModel = receive.data;
//            if (correctModel.is_buy.intValue == 0) {
//                TopicCorrectController *topVC = [[TopicCorrectController alloc] init];
//                topVC.correctModel = correctModel;
//                [SettingObject pushviewController:topVC];
//            }else{
//                BuyCourseController *buyVC = [[BuyCourseController alloc] init];
//                buyVC.buyCourseDic = dic;
//                [SettingObject pushviewController:buyVC];
//            }
//        }
//    } failure:^(id reslut) {
//        
//    }];
}

#pragma mark - 极光分享
//- (void)shareViewAddSubview:(UIView *)view withMessage:(JSHAREMessage *)message andDic:(NSDictionary*)dic{
//    self.message = message;
//    [self.shareView showWithContentType:JSHARELink];
//    if (!view) {
//        view = kKeyWindow;
//    }
//    //1=智能刷题、高频错题、考点练习 2=历年真题 3=直播分享 4=点播分享 5=面授分享 6=申论分享 7=备考分享 8=智能刷题报告 9=套卷报告 （传参）10=综合评估
//    SGParameter *parameter = [[SGParameter alloc] init];
//    parameter.body.data = dic;
//    NSString *url = [NSString stringWithFormat:@"%@%@",[OtherNetworking sharedManager].STRURL,@"Apifavorite/share_course_question"];
//    [MBProgressHUD showLoadingImageToView:kKeyWindow];
//    [SGHttpTool POST:url parameter:parameter sucess:^(id result) {
//        [MBProgressHUD hideHUDForView:kKeyWindow animated:YES];
//        NSDictionary *dataDic = [result objectForKey:@"data"];
//        NSInteger code = [[result objectForKey:@"code"] intValue];
//        if (code != 2000) {
//            [MBProgressHUD showTextOnly:view message:[result objectForKey:RESPONSE_MSG]];
//        } else {
//
//            self.message.title = [dataDic objectForKey:@"share_title"];
//            self.message.text = [dataDic objectForKey:@"share_content"];
//            self.message.url = [dataDic objectForKey:@"share_url"];
//            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[dataDic objectForKey:@"share_image"]]];
//            self.message.image = imageData;//[NSData dataWithBase64EncodedString:[dataDic objectForKey:@"share_image"]];
//            [view addSubview:self.shareView];
//        }
//    } failure:^(id reslut) {
//        [MBProgressHUD hideHUDForView:kKeyWindow animated:YES];
//        [MBProgressHUD showTextOnly:view message:@"获取分享信息失败"];
//    }];
//}
- (ShareView *)shareView {
    if (!_shareView) {
//        _shareView = [ShareView getFactoryShareViewWithCallBack:^(JSHAREPlatform platform, JSHAREMediaType type) {
//            [self shareLinkWithPlatform:platform];
//            switch (type) {
//                case JSHARELink:
//                    [self shareLinkWithPlatform:platform];
//                    break;
//                default:
//                    break;
//            }
//        }];
        //[self.superView addSubview:self.shareView];
    }
    return _shareView;
}
//- (void)shareLinkWithPlatform:(JSHAREPlatform)platform {
//    self.message.platform = platform;
//    [JSHAREService share:self.message handler:^(JSHAREState state, NSError *error) {
//        NSString *string = @"";
//        switch (state) {
//            case JSHAREStateFail:
//                string = @"分享失败";
//                [MBProgressHUD showTextOnly:kKeyWindow message:string];
//                NSLog(@"分享失败");
//                break;
//            case JSHAREStateSuccess:
//                NSLog(@"分享成功");
//                string = @"分享成功";
//                [MBProgressHUD showTextOnly:kKeyWindow message:string];
//                break;
//            case JSHAREStateCancel:
//                NSLog(@"分享失败-取消");
//                string = @"取消分享";
//                [MBProgressHUD showTextOnly:kKeyWindow message:string];
//                break;
//            case JSHAREStateUnknown:
//                NSLog(@"分享失败-未知");
//                //string = @"分享失败";
//                break;
//            default:
//                break;
//        }
//    }];
//}
@end
